package uk.co.kevinlockwood.kol.messages;

import uk.co.kevinlockwood.kol.droid.DroidHelpers;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.view.MotionEvent;
import android.widget.TextView;

public class LinkMovementMethodIntercept extends LinkMovementMethod {
	@Override
	protected boolean left(TextView widget, Spannable buffer) {
		DroidHelpers.trace("LIMM.left: widget=[",widget,"] buffer=[",buffer,"]");
		try {
			return super.left(widget, buffer);
		} catch (Exception e) {
			// it was not meant to be... it will open anything it can, and anything it can't (ie. player name links) we leave for now
		}
		return false;
	}

	@Override
	protected boolean right(TextView widget, Spannable buffer) {
		DroidHelpers.trace("LIMM.right: widget=[",widget,"] buffer=[",buffer,"]");
		try {
			return super.right(widget, buffer);
		} catch (Exception e) {
			// it was not meant to be... it will open anything it can, and anything it can't (ie. player name links) we leave for now
		}
		return false;
	}

	@Override
	protected boolean up(TextView widget, Spannable buffer) {
		DroidHelpers.trace("LIMM.up: widget=[",widget,"] buffer=[",buffer,"]");
		try {
			return super.up(widget, buffer);
		} catch (Exception e) {
			// it was not meant to be... it will open anything it can, and anything it can't (ie. player name links) we leave for now
		}
		return false;
	}

	@Override
	protected boolean down(TextView widget, Spannable buffer) {
		DroidHelpers.trace("LIMM.down: widget=[",widget,"] buffer=[",buffer,"]");
		try {
			return super.down(widget, buffer);
		} catch (Exception e) {
			// it was not meant to be... it will open anything it can, and anything it can't (ie. player name links) we leave for now
		}
		return false;
	}

	@Override
	public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
		DroidHelpers.trace("LIMM.onTouchEvent: widget=[",widget,"] buffer=[",buffer,"] event=[",event,"]");
		try {
			return super.onTouchEvent(widget, buffer, event);
		} catch (Exception e) {
			// it was not meant to be... it will open anything it can, and anything it can't (ie. player name links) we leave for now
		}
		return false;
	}

	public static MovementMethod getInstance() {
		return new LinkMovementMethodIntercept();
	}
}
